package cn.moukou.dictator.vo;

import cn.moukou.dictator.pojo.Student;
import cn.moukou.dictator.pojo.node.KVNode;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Map;

@Data
public class NodeVO {
    private Long id;
    private String nodeType;
    private String path;
    Map<String, Object> payload;

    public NodeVO(KVNode node) {
        this.id = node.getId();
        this.nodeType = node.getNodeType();
        this.path = node.getPath();

        switch (node.getNodeType()) {
            case "activity":
                payload = JSON.parseObject(JSON.toJSONString(node.getActivity()));
                break;
            case "award":
                payload = JSON.parseObject(JSON.toJSONString(node.getAward()));
                break;
            case "class_room":
                payload = JSON.parseObject(JSON.toJSONString(node.getClassRoom()));
                break;
            case "competition":
                payload = JSON.parseObject(JSON.toJSONString(node.getCompetition()));
                break;
            case "student":
                payload = JSON.parseObject(JSON.toJSONString(node.getStudent()));
                break;
            case "student_organization":
                payload = JSON.parseObject(JSON.toJSONString(node.getStudentOrganization()));
                break;
            case "teacher":
                payload = JSON.parseObject(JSON.toJSONString(node.getTeacher()));
                break;
        }
    }
}
